#ifndef CENTERCOMBOBOX_H
#define CENTERCOMBOBOX_H

#include <QObject>
#include <QWidget>
#include <QComboBox>
#include <QLineEdit>
#include <QStyleFactory>
#include <QListWidget>
#include <QListWidgetItem>
#include <QEvent>
#include <QDebug>
#include <QStandardItemModel>
#include <QMouseEvent>
#include <QTime>
#include <QScroller>
#include <QScrollBar>
#include <QMutexLocker>
#include <QMutex>

//居中显示的下拉框
class centerCombobox : public QComboBox
{
    friend QScroller;
    Q_OBJECT
public:
    explicit centerCombobox(QWidget *parent = nullptr);
    ~centerCombobox();

private:
    QLineEdit *lineEdit = 0;                                    //显示框
    bool showP = false;                                         //是否下拉显示
    QDateTime timer;                                            //显示时间，用于判断显示下拉列表还是不显示下拉列表
    QListView *listView = nullptr;
    QStandardItemModel* model = nullptr;
    QScroller *pScroller = nullptr;

public:
    bool eventFilter(QObject *watched, QEvent *event) override; //事件过滤处理
    virtual void showPopup() override;                          //显示下拉项
    virtual void hidePopup() override;                          //隐藏下拉项
    void addItem(const QString &text) ;                         //添加单个子项
    void addItem(const QString &atext, const QVariant &auserData);
    void addItems(const QStringList &texts) ;                   //添加多个子项
    void instertItem(int aindex, const QString &atext);         //插入单个子项
    void instertItems(int aindex,const QStringList &atexts);    //插入多个子项
    void setFont(const QFont &) ;                               //设置字体
    void initSheet();                                           //初始化风格
signals:
    void signalIndexChanged(QString text);

};

#endif // CENTERCOMBOBOX_H
